import 'package:flutter/material.dart';

/**
 * Popup弹出
 */
class PopupMenuButonDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _PopupMenuButonState();
  }
}

class _PopupMenuButonState extends State<PopupMenuButonDemo> {
  String _currSelectContent = 'Home';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('PopupMenuButonDemo'),
        elevation: 0.0,
      ),
      body: Container(
        padding: EdgeInsets.all(8.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(_currSelectContent),
                SizedBox(
                  width: 10.0,
                ),
                PopupMenuButton(
                    // 选择之后回调
                    onSelected: (value) {
                      debugPrint('选择之后回调: $value');
                      setState(() {
                        _currSelectContent = value;
                      });
                    },
                    itemBuilder: (BuildContext context) => [
                          PopupMenuItem(
                            value: 'Home',
                            child: Text('Home'),
                          ),
                          PopupMenuItem(
                            value: 'About',
                            child: Text('About'),
                          ),
                          PopupMenuItem(
                            value: 'Order',
                            child: Text('Order'),
                          ),
                        ])
              ],
            ),
          ],
        ),
      ),
    );
  }
}
